<?php

namespace App\V3\V3_2_6\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\V3\V3_2_6\Services\StorageSpaceOrderService;
use Illuminate\Validation\Rule;

class StorageSpaceOrderController extends BaseController
{

    /**
     * 微信支付
     * @param pay_type 支付类型 1小程序 2app
     * @param space_id 购买存储空间id
     * @param code     微信用户CODE获取open_id使用
     */
    public function WechatPay(Request $request)
    {
        //参数验证
        $validator = Validator::make($data = $request->all(), [
            'pay_type' => [
                'required',
                Rule::In([1, 2]),
            ],//支付类型 1小程序 2app
        ],
            [

                'pay_type.required' => '请选择类型',
                'pay_type.in' => '类型不合法，请重新选择',
                #'code.required' => 'code不能为空',
            ]);

        //参数错误响应
        if ($info = $validator->errors()->first()) {
            return $this->fail('', $info);
        }

        return response()->json(StorageSpaceOrderService::createOrder($this->getMainUserId(),$data));
    }
}
